/**
 * Created by 123 on 2016/10/9.
 */
public class MergeSort {
    public static String[] MergeSort(String[] array) {
        Sort(array, 0, array.length - 1);
        return array;
    }
    private static void Sort(String[] array, int low, int high) {
        if(low>=high)
            return;
        int mid = (low + high) / 2;
        Sort(array, low, mid);
        Sort(array, mid + 1, high);
        merge(array,low, mid, high);
    }
    private static void merge(String[] array, int low, int mid, int high) {
        String[] temp = new String[array.length];
        int mid2 = mid + 1;
        int tempIndex = low;
        int copyIndex=low;
        while(low <=mid && mid2 <= high) {
            System.out.print(array[low].split("\t").toString());
            if (Integer.parseInt(array[low].split("\t")[7]) <= Integer.parseInt(array[mid2].split("\t")[7]))
                temp[tempIndex++] = array[low++];
            else
                temp[tempIndex++] = array[mid2++];
        }
        while (low <=mid) {
            temp[tempIndex++] = array[low++];
        }
        while ( mid2 <= high ) {
            temp[tempIndex++] = array[mid2++];
        }
        while(copyIndex<=high){
            array[copyIndex]=temp[copyIndex];
            copyIndex++;
        }
    }
}

